<?php
include_once 'kahlua.ini';
include 'classes/utils/smarty_connect.php';
include_once 'classes/handlers/videosHandler.php';
include_once 'classes/db.php';
include_once 'classes/classNotas.php';
include_once 'classes/classUtils.php';
include_once 'classes/recaptchalib.php';
include_once 'classes/classComentarios.php';

$notaID = $_GET["nota"];
$arrVideos = videosHandler::getTop3Videos();


//post comments
$comments = new Comentarios();
if(isset($_POST["notaid"])){

$privatekey = "6LcA070SAAAAAApBM4SrzVdXyYqNBBdr8WLJRA9z";

$resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
  die ("El reCAPTCHA no se lleno bien, por favor intenta de nuevo." .
       "(reCAPTCHA dijo: " . $resp->error . ") <a href='javascript:history(-1)'>Volver...</a>");
}else{
	$notaid		= $_POST["notaid"];
	$userName	= htmlentities($_POST["userName"],ENT_COMPAT, 'UTF-8');
	$email      = htmlentities($_POST["userEmail"],ENT_COMPAT, 'UTF-8');
	$comentario = htmlentities($_POST["txtComment"],ENT_COMPAT, 'UTF-8');
	
		if($userName!= "Nombre" && $email != "Email" && $comentario != "Escribe tu comentario Aqui."){
			$comments->sendComments($notaid, $userName, $email, $comentario);
		}
	}
}

$myNota = new Notas();
$arrNota = $myNota->getNota($notaID);
//$arrColumna = $myNota->getColumnaRodrigo();
$arrColumna = $myNota->getColumnaStaff();

//Comentarios
$commentList = $comments->getComments($notaID);

//recaptcha
$publickey = "6LcA070SAAAAAEl1cBPea8d8VYrcnbpZovITFYLk";
$recaptcha = recaptcha_get_html($publickey);

$myNota->verNota($notaID);

//en Resumen
$enResumen = $myNota->getEnResumen();

$smarty = new smarty_connect;
$smarty->template_dir = '/projects/newmasmedio/templates';
$smarty->assign("CSS", array("newmasmedio.css", "notas.css"));
$smarty->assign("JS", array("jquery-1.3.2.js","masmedio.js", "verNota.js"));
$smarty->assign("title", "MasMedio.com | ".$arrNota["titulo"]);
$smarty->assign("arrVideos", $arrVideos);
$smarty->assign("notaID", $notaID);
$smarty->assign("arrNota", $arrNota);
$smarty->assign("publickey", $publickey);
$smarty->assign("recaptcha", $recaptcha);
$smarty->assign("arrColumna", $arrColumna);
$smarty->assign("commentList", $commentList);
$smarty->assign("enResumen", $enResumen);
$smarty->display('verNota.tpl');